package com.yy.controller.user;

import com.yy.controller.service.AdminUserService;
import com.yy.controller.service.UserService;
import com.yy.dto.AdminUserDTO;
import com.yy.dto.AdminUserLoginDTO;
import com.yy.dto.AdminUserPageQueryDTO;
import com.yy.entity.User;
import com.yy.result.PageResult;
import com.yy.result.Result;
import com.yy.vo.AdminUserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "客户端用户相关接口")
public class UserController {
    @Autowired
    private AdminUserService adminUserService;
    @Autowired
    private UserService userService;

    /**
     * 用户登录
     *
     * @param user
     * @return
     */
    @PostMapping("/login")
    @CrossOrigin
    @ApiOperation(value = "用户登录")
    public Result login(@RequestBody User user) {
        log.info("用户信息:{}", user);
        User u = userService.login(user);
        return Result.success(u);
    }
    @PostMapping("/yzmLogin")
    @CrossOrigin
    @ApiOperation(value = "验证码登录")
    public Result yzmLogin(@RequestBody User user) {
        log.info("用户信息:{}", user);
        User u = userService.yzmLogin(user);
        return Result.success(u);
    }


    @PostMapping("/update")
    @CrossOrigin
    @ApiOperation(value = "修改密码")
    public Result<User> update(@RequestBody User user) {
        log.info("用户信息:{}", user);
        userService.update(user);
        return Result.success(user);
    }

    @GetMapping("/sms")
    @CrossOrigin
    @ApiOperation("获取验证")
    public Result getSms() {
        return Result.success("模拟发送,验证码为:2245");
    }


    /**
     * 注册账号
     *
     * @return
     */
    @PostMapping("/register")
    @CrossOrigin
    @ApiOperation(value ="注册账号")
    public Result register(@RequestBody User user) {
        log.info("新增账号:{}", user);
        userService.addUser(user);
        return Result.success();
    }
}
